// wenshidu/chufang_lsit/chufang_lsit.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
var shuzong = []
var shu = []
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    title: '上传处方',
    heights: '',
    list_gao: '',
    list: [],
    page: 1,
    gongwu: false,
    list_gaos: '',
    start: '开始时间',
    starts: '',
    endtime: '结束时间',
    endtimes: '',
    tablist:['处方列表','未上传处方说明'],
    cutterIndex:0,
  },
  xuanTab(e){
    var index = e.currentTarget.dataset.index
    this.setData({
      cutterIndex: index,
      page:1,
      list:[],
      start: '开始时间',
      starts: '',
      endtime: '结束时间',
      endtimes: '',

    })
    // if(index==0){
    //   this.chuf_lsit()
    // }else if(index==1){
    //    this.chuf_lsit()
    // }
       this.chuf_lsit()

  },
  bindkaishi(e) {
    this.setData({
      start: e.detail.value,
      starts: e.detail.value,
    })
    this.chuf_lsit()
  },
  bindjieshu(e) {
    this.setData({
      endtime: e.detail.value,
      endtimes: e.detail.value,
    })
    this.chuf_lsit()
  },
  // 销售记录
  xsjl(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/wenshidu/chu_xiaoxq/chu_xiaoxq?id=' + id,
    })
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.list
    this.setData({
      page: (this.data.page) + 1
    })
    this.chuf_lsit();
  },
  // 编辑
  bianji(e) {
    var id = e.currentTarget.dataset.id
    var cutterIndex = this.data.cutterIndex
    if(cutterIndex==0){
      var state = 1
    }else if(cutterIndex==1){
      var state = 3
    }
    wx.navigateTo({
      url: '/wenshidu/add_chufang/add_chufang?state='+state+'&id=' + id,
    })
  },
  // 删除
  shanchu(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    wx.showModal({
      title: '确定要删除吗?',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          that.shan_jie(id)
        } else {}
      }
    })
  },
  shan_jie(id) {
    var cutterIndex = this.data.cutterIndex
    if(cutterIndex==0){
      var url = yuming + 'Jinghexincheng/jhxc_chufangyao_delete'
      var data ={
        shopId: wx.getStorageSync('shopId'),
        page: this.data.page,
        id: id,
      }
    }else if(cutterIndex==1){
      var url = yuming + 'Jinghexincheng/chufangyao_nolog_del'
      var data ={
        // shopId: wx.getStorageSync('shopId'),
        // page: this.data.page,
        id: id,
      }
    }

    this.myRequest(url, data, "POST").then(res => {
      var shu = res.data.data
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      var that = this
      if (res.data.code == 200) {
        setTimeout(function () {
          that.chuf_lsit()
        }, 1000)
      }
    })
  },
  // 放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    var arr = []
    for (let i in list) {
      arr.push(list[i]); //属性
    }
    wx.previewImage({
      current: img,
      urls: arr
    })
    console.log(arr);
  },
  tianjia(e) {
    var type = e.currentTarget.dataset.type
    wx.navigateTo({
      url: '/wenshidu/add_chufang/add_chufang?state='+type,
    })
  },
  chuf_lsit() {
    var cutterIndex = this.data.cutterIndex
    if(cutterIndex==0){
      var url = yuming + 'Jinghexincheng/jhxc_chufangyao_list'  //处方列表
      var data ={
        shopId: wx.getStorageSync('shopId'),
        page: this.data.page,
        begintime:this.data.starts,
        endtime:this.data.endtimes
      }
    }else if(cutterIndex==1){
      var url = yuming + 'Jinghexincheng/chufangyao_nolog_list'//未上传处方说明
      var data ={
        shopId: wx.getStorageSync('shopId'),
        page: this.data.page,
        signtime:this.data.starts,
        endtime:this.data.endtimes,
        keywords:'',
      }
    }
    this.myRequest(url, data, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        shu = res.data.data
        if (this.data.page != 1) {
          if (shu.length != 10) {
            this.setData({
              gongwu: true
            })
          }
        }
        this.setData({
          list: shuzong.concat(shu), //地址列表
        })
      }

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      list_gao: wx.getMenuButtonBoundingClientRect().top + 50,
      list_gaos: wx.getMenuButtonBoundingClientRect().top + 140,
    })

  },
  // 返回
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.chuf_lsit()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})